home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / xulrunner-1.9.0.14 / chrome / toolkit.jar / content / mozapps / xpinstall / xpinstallConfirm.js < prev    next >
Encoding:
JavaScript  |  2008-03-08  |  4.6 KB  |  150 lines

  1. //@line 37 "/build/buildd/xulrunner-1.9-1.9.0.14+build2+nobinonly/mozilla/toolkit/mozapps/xpinstall/content/xpinstallConfirm.js"
  2.  
  3. var XPInstallConfirm = 
  4.   _param: null
  5. };
  6.  
  7.  
  8. XPInstallConfirm.init = function ()
  9. {
  10.   var _installCountdown;
  11.   var _installCountdownInterval;
  12.   var _focused;
  13.   var _timeout;
  14.  
  15.   var bundle = document.getElementById("xpinstallConfirmStrings");
  16.   
  17.   this._param = window.arguments[0].QueryInterface(Components.interfaces.nsIDialogParamBlock);
  18.   if (!this._param)
  19.     close();
  20.   
  21.   this._param.SetInt(0, 1); // The default return value is "Cancel"
  22.   
  23.   var _installCountdownLength = 5;
  24.   try {
  25.     var prefs = Components.classes["@mozilla.org/preferences-service;1"]
  26.                           .getService(Components.interfaces.nsIPrefBranch);
  27.     var delay_in_milliseconds = prefs.getIntPref("security.dialog_enable_delay");
  28.     _installCountdownLength = Math.round(delay_in_milliseconds / 500);
  29.   } catch (ex) { }
  30.   
  31.   var itemList = document.getElementById("itemList");
  32.   
  33.   var numItemsToInstall = this._param.GetInt(1);
  34.   for (var i = 0; i < numItemsToInstall; ++i) {
  35.     var installItem = document.createElement("installitem");
  36.     itemList.appendChild(installItem);
  37.  
  38.     installItem.name = this._param.GetString(i);
  39.     installItem.url = this._param.GetString(++i);
  40.     var icon = this._param.GetString(++i);
  41.     if (icon != "")
  42.       installItem.icon = icon;
  43.     var cert = this._param.GetString(++i);
  44.     if (cert)
  45.       installItem.cert = bundle.getFormattedString("signed", [cert]);
  46.     else
  47.       installItem.cert = bundle.getString("unverified");
  48.     installItem.signed = cert ? "true" : "false";
  49.   }
  50.   
  51.   var introString = bundle.getString("itemWarnIntroSingle");
  52.   if (numItemsToInstall > 4)
  53.     introString = bundle.getFormattedString("itemWarnIntroMultiple", [numItemsToInstall / 4]);
  54.   if (this._param.objects && this._param.objects.length)
  55.     introString = this._param.objects.queryElementAt(0, Components.interfaces.nsISupportsString).data;
  56.   var textNode = document.createTextNode(introString);
  57.   var introNode = document.getElementById("itemWarningIntro");
  58.   while (introNode.hasChildNodes())
  59.     introNode.removeChild(introNode.firstChild);
  60.   introNode.appendChild(textNode);
  61.   
  62.   var okButton = document.documentElement.getButton("accept");
  63.   okButton.focus();
  64.  
  65.   function okButtonCountdown() {
  66.     _installCountdown -= 1;
  67.  
  68.     if (_installCountdown < 1) {
  69.       okButton.label = bundle.getString("installButtonLabel");
  70.       okButton.disabled = false;
  71.       clearInterval(_installCountdownInterval);
  72.     }
  73.     else
  74.       okButton.label = bundle.getFormattedString("installButtonDisabledLabel", [_installCountdown]);
  75.   }
  76.  
  77.   function myfocus() {
  78.     // Clear the timeout if it exists so only the last one will be used.
  79.     if (_timeout)
  80.       clearTimeout(_timeout);
  81.  
  82.     // Use setTimeout since the last focus or blur event to fire is the one we
  83.     // want
  84.     _timeout = setTimeout(setWidgetsAfterFocus, 0);
  85.   }
  86.  
  87.   function setWidgetsAfterFocus() {
  88.     if (_focused)
  89.       return;
  90.  
  91.     _installCountdown = _installCountdownLength;
  92.     _installCountdownInterval = setInterval(okButtonCountdown, 500);
  93.     okButton.label = bundle.getFormattedString("installButtonDisabledLabel", [_installCountdown]);
  94.     _focused = true;
  95.   }
  96.  
  97.   function myblur() {
  98.     // Clear the timeout if it exists so only the last one will be used.
  99.     if (_timeout)
  100.       clearTimeout(_timeout);
  101.  
  102.     // Use setTimeout since the last focus or blur event to fire is the one we
  103.     // want
  104.     _timeout = setTimeout(setWidgetsAfterBlur, 0);
  105.   }
  106.  
  107.   function setWidgetsAfterBlur() {
  108.     if (!_focused)
  109.       return;
  110.  
  111.     // Set _installCountdown to the inital value set in setWidgetsAfterFocus
  112.     // plus 1 so when the window is focused there is immediate ui feedback.
  113.     _installCountdown = _installCountdownLength + 1;
  114.     okButton.label = bundle.getFormattedString("installButtonDisabledLabel", [_installCountdown]);
  115.     okButton.disabled = true;
  116.     clearInterval(_installCountdownInterval);
  117.     _focused = false;
  118.   }
  119.  
  120.   function myUnload() {
  121.     document.removeEventListener("focus", myfocus, true);
  122.     document.removeEventListener("blur", myblur, true);
  123.     window.removeEventListener("unload", myUnload, false);
  124.   }
  125.  
  126.   if (_installCountdownLength > 0) {
  127.     document.addEventListener("focus", myfocus, true);
  128.     document.addEventListener("blur", myblur, true);
  129.     window.addEventListener("unload", myUnload, false);
  130.  
  131.     okButton.disabled = true;
  132.     setWidgetsAfterFocus();
  133.   }
  134.   else
  135.     okButton.label = bundle.getString("installButtonLabel");
  136. }
  137.  
  138. XPInstallConfirm.onOK = function ()
  139. {
  140.   this._param.SetInt(0, 0);
  141.   return true;
  142. }
  143.  
  144. XPInstallConfirm.onCancel = function ()
  145. {
  146.   this._param.SetInt(0, 1);
  147.   return true;
  148. }
  149.